package JavaDowork.pratice4;

/*
计算1！+2！+3！+…+n！并输出。
【要求】最后一位数n由控制台输入。
 */

import java.util.Scanner;

public class Q2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("整数n: ");
        int n = scanner.nextInt();
        scanner.close();
        long sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += factorial(i);
        }
        System.out.println(sum);
    }

    public static long factorial(int n) {
        long fact = 1;
        for (int i = 1; i <= n; i++) {
            fact *= i;
        }
        return fact;
    }

}
